package utils;

import java.util.SortedSet;

import data.ClusteredNode;
import data.Gene;

public class AverageLink extends ClusterDistanceCalculator {

	@Override
	public double distance(ClusteredNode c1, ClusteredNode c2) {
		GeneDistanceCalculator calculator = getGeneDistanceCalculator();
		double sum=0;
		int count=0;
		SortedSet<Gene> genes1 = c1.getGenes();
		SortedSet<Gene> genes2 = c2.getGenes();
		for (Gene g1:genes1) { 
			for (Gene g2:genes2) { 
				sum+=calculator.distance(g1,g2);
				count++;
			}
		}
		return sum/count;
	}

}
